from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-17 14:12:35.456712
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 17, Aug, 2021
Time: 14:12:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6855
Nobs: 386.000 HQIC: -46.2421
Log likelihood: 4155.92 FPE: 5.73481e-21
AIC: -46.6078 Det(Omega_mle): 4.55562e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.442204 0.095672 4.622 0.000
L1.Burgenland 0.110196 0.049608 2.221 0.026
L1.Kärnten -0.115869 0.024427 -4.743 0.000
L1.Niederösterreich 0.169931 0.106596 1.594 0.111
L1.Oberösterreich 0.120047 0.105346 1.140 0.254
L1.Salzburg 0.290205 0.051729 5.610 0.000
L1.Steiermark 0.014856 0.068556 0.217 0.828
L1.Tirol 0.120587 0.054089 2.229 0.026
L1.Vorarlberg -0.115781 0.048819 -2.372 0.018
L1.Wien -0.029972 0.094460 -0.317 0.751
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.005049 0.225197 0.022 0.982
L1.Burgenland -0.052292 0.116770 -0.448 0.654
L1.Kärnten 0.034937 0.057498 0.608 0.543
L1.Niederösterreich -0.257030 0.250909 -1.024 0.306
L1.Oberösterreich 0.553825 0.247967 2.233 0.026
L1.Salzburg 0.315022 0.121762 2.587 0.010
L1.Steiermark 0.111277 0.161368 0.690 0.490
L1.Tirol 0.302541 0.127317 2.376 0.017
L1.Vorarlberg -0.012179 0.114912 -0.106 0.916
L1.Wien 0.011257 0.222344 0.051 0.960
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.252318 0.048833 5.167 0.000
L1.Burgenland 0.096759 0.025321 3.821 0.000
L1.Kärnten -0.003079 0.012468 -0.247 0.805
L1.Niederösterreich 0.233347 0.054408 4.289 0.000
L1.Oberösterreich 0.156388 0.053771 2.908 0.004
L1.Salzburg 0.036550 0.026404 1.384 0.166
L1.Steiermark 0.010522 0.034992 0.301 0.764
L1.Tirol 0.072755 0.027608 2.635 0.008
L1.Vorarlberg 0.056665 0.024918 2.274 0.023
L1.Wien 0.088730 0.048214 1.840 0.066
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.193982 0.047672 4.069 0.000
L1.Burgenland 0.042768 0.024719 1.730 0.084
L1.Kärnten -0.006590 0.012172 -0.541 0.588
L1.Niederösterreich 0.122386 0.053115 2.304 0.021
L1.Oberösterreich 0.313483 0.052492 5.972 0.000
L1.Salzburg 0.101884 0.025776 3.953 0.000
L1.Steiermark 0.138641 0.034160 4.059 0.000
L1.Tirol 0.076259 0.026952 2.829 0.005
L1.Vorarlberg 0.055308 0.024326 2.274 0.023
L1.Wien -0.039096 0.047068 -0.831 0.406
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207607 0.095211 2.180 0.029
L1.Burgenland -0.062119 0.049369 -1.258 0.208
L1.Kärnten -0.036228 0.024309 -1.490 0.136
L1.Niederösterreich 0.082888 0.106082 0.781 0.435
L1.Oberösterreich 0.198781 0.104838 1.896 0.058
L1.Salzburg 0.264330 0.051480 5.135 0.000
L1.Steiermark 0.074975 0.068225 1.099 0.272
L1.Tirol 0.123617 0.053828 2.297 0.022
L1.Vorarlberg 0.115097 0.048584 2.369 0.018
L1.Wien 0.035293 0.094005 0.375 0.707
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.026209 0.074456 0.352 0.725
L1.Burgenland 0.029407 0.038607 0.762 0.446
L1.Kärnten 0.050655 0.019010 2.665 0.008
L1.Niederösterreich 0.198357 0.082957 2.391 0.017
L1.Oberösterreich 0.346781 0.081984 4.230 0.000
L1.Salzburg 0.046842 0.040258 1.164 0.245
L1.Steiermark -0.001823 0.053352 -0.034 0.973
L1.Tirol 0.114257 0.042094 2.714 0.007
L1.Vorarlberg 0.061556 0.037993 1.620 0.105
L1.Wien 0.129227 0.073512 1.758 0.079
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183850 0.090839 2.024 0.043
L1.Burgenland 0.019963 0.047102 0.424 0.672
L1.Kärnten -0.057552 0.023193 -2.481 0.013
L1.Niederösterreich -0.118877 0.101211 -1.175 0.240
L1.Oberösterreich 0.194838 0.100024 1.948 0.051
L1.Salzburg 0.030910 0.049116 0.629 0.529
L1.Steiermark 0.299488 0.065092 4.601 0.000
L1.Tirol 0.494022 0.051357 9.619 0.000
L1.Vorarlberg 0.065826 0.046353 1.420 0.156
L1.Wien -0.109471 0.089689 -1.221 0.222
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164324 0.098872 1.662 0.097
L1.Burgenland -0.004805 0.051268 -0.094 0.925
L1.Kärnten 0.062763 0.025244 2.486 0.013
L1.Niederösterreich 0.193501 0.110161 1.757 0.079
L1.Oberösterreich -0.120487 0.108869 -1.107 0.268
L1.Salzburg 0.244981 0.053459 4.583 0.000
L1.Steiermark 0.153252 0.070848 2.163 0.031
L1.Tirol 0.051786 0.055898 0.926 0.354
L1.Vorarlberg 0.121361 0.050452 2.405 0.016
L1.Wien 0.136485 0.097620 1.398 0.162
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.493938 0.053642 9.208 0.000
L1.Burgenland -0.015254 0.027815 -0.548 0.583
L1.Kärnten -0.009256 0.013696 -0.676 0.499
L1.Niederösterreich 0.198938 0.059766 3.329 0.001
L1.Oberösterreich 0.259582 0.059066 4.395 0.000
L1.Salzburg 0.020826 0.029004 0.718 0.473
L1.Steiermark -0.023349 0.038438 -0.607 0.544
L1.Tirol 0.067787 0.030327 2.235 0.025
L1.Vorarlberg 0.057885 0.027372 2.115 0.034
L1.Wien -0.048711 0.052962 -0.920 0.358
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.019888 0.070797 0.138866 0.126783 0.038753 0.068071 -0.001942 0.184074
Kärnten 0.019888 1.000000 -0.055330 0.129322 0.045406 0.068877 0.458461 -0.093605 0.098085
Niederösterreich 0.070797 -0.055330 1.000000 0.291483 0.092049 0.274327 0.015203 0.148886 0.256563
Oberösterreich 0.138866 0.129322 0.291483 1.000000 0.175324 0.294555 0.165564 0.120386 0.133337
Salzburg 0.126783 0.045406 0.092049 0.175324 1.000000 0.130000 0.050528 0.108985 0.051392
Steiermark 0.038753 0.068877 0.274327 0.294555 0.130000 1.000000 0.127081 0.087335 -0.021227
Tirol 0.068071 0.458461 0.015203 0.165564 0.050528 0.127081 1.000000 0.039169 0.120898
Vorarlberg -0.001942 -0.093605 0.148886 0.120386 0.108985 0.087335 0.039169 1.000000 -0.048351
Wien 0.184074 0.098085 0.256563 0.133337 0.051392 -0.021227 0.120898 -0.048351 1.000000